package com.example.viewpager_demo;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by Lian on 2016/5/9.
 */
public class AutoScrollPagerAdapter extends PagerAdapter
{
    private List<View> mViewList;
    public AutoScrollPagerAdapter(List<View> viewList)
    {
        this.mViewList = viewList;
    }
    @Override
    public int getCount()
    {
        return Integer.MAX_VALUE;
    }

    //返回实际的条目的个数
    public int getItemCount()
    {
        return mViewList.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position)
    {
        View view = mViewList.get(position%mViewList.size());
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object)
    {
        View view = mViewList.get(position%mViewList.size());
        container.removeView(view);
    }

    @Override
    public boolean isViewFromObject(View view, Object object)
    {
        return view==object;
    }
}
